//
//  MSShowPictureVC.m
//  MS
//
//  Created by Yuan on 13-2-14.
//  Copyright (c) 2013年 He Yuan. All rights reserved.
//

#import "MSShowPictureVC.h"
#import "MSAppDelegate.h"
#import "PlaceholderTextView.h"

#import <QuartzCore/QuartzCore.h>

@interface MSShowPictureVC ()<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate>
{
    BOOL isModalViewController;
    
    UIImageView *uploadImageView;
    
    PlaceholderTextView *txtView;
    
    UIButton *rorateBtn;
    
    UIView *toolBar;
    
    NSInteger maxCount;
    
    BOOL isSelectImage;
    
    NSInteger flag;
    NSMutableDictionary *tagsDict;
    NSMutableArray *tbArray;
    UIView *tagsView;
    UITableView *tb;
}
@property(nonatomic,retain)UIImageView *uploadImageView;

@property(nonatomic,retain)PlaceholderTextView *txtView;

@property(nonatomic,retain)UIButton *rorateBtn;

@property(nonatomic,retain)UIView *toolBar;

@property (nonatomic,retain)UITableView *tb;

@property (nonatomic,retain)UIView *tagsView;

@property (nonatomic,retain)NSMutableDictionary *tagsDict;

@property (nonatomic,retain)NSMutableArray *tbArray;

@end

@implementation MSShowPictureVC

@synthesize uploadImageView;

@synthesize txtView;

@synthesize rorateBtn;

@synthesize toolBar;

@synthesize tagsView;

@synthesize tbArray ;

@synthesize tb ;

@synthesize tagsDict;

- (id)initWithModalViewController:(BOOL)ismodal
{
    self = [super init];
    
    if (self)
    {
        isModalViewController = ismodal;
        
        maxCount = 100;
                
        tagsDict = [[NSMutableDictionary alloc]init];
        
        tbArray = [[NSMutableArray alloc]initWithObjects:
                    [NSDictionary dictionaryWithObjectsAndKeys:@"性别",@"title",[NSArray arrayWithObjects:@"女发",@"男发", nil],@"array", nil],
                    [NSDictionary dictionaryWithObjectsAndKeys:@"发长",@"title",[NSArray arrayWithObjects:@"短发",@"长发",@"中发", nil],@"array", nil],
                    [NSDictionary dictionaryWithObjectsAndKeys:@"卷度",@"title",[NSArray arrayWithObjects:@"大卷",@"中卷",@"小卷",@"直发", nil],@"array", nil],
                    [NSDictionary dictionaryWithObjectsAndKeys:@"颜色",@"title",[NSArray arrayWithObjects:@"黄色",@"红色",@"黑色",@"紫色",@"咖啡", nil],@"array", nil],
                    [NSDictionary dictionaryWithObjectsAndKeys:@"风格",@"title",[NSArray arrayWithObjects:@"淑女",@"个性",@"时尚",@"职业", nil],@"array", nil],
                    [NSDictionary dictionaryWithObjectsAndKeys:@"季型",@"title",[NSArray arrayWithObjects:@"春季型",@"夏季型",@"秋季型",@"冬季型", nil],@"array", nil],
                    [NSDictionary dictionaryWithObjectsAndKeys:@"脸型",@"title",[NSArray arrayWithObjects:@"瓜子脸",@"鹅蛋脸",@"圆形脸",@"洋梨脸",@"方形脸",@"长形脸",@"菱形脸", nil],@"array", nil],
                    nil];
    }
    
    return self;
}

-(void)loadView
{
    [super loadView];
    
    CGRect rect = CGRectMake(0, 0, 230, 155);
    txtView = [[PlaceholderTextView alloc]initWithFrame:rect drawoffsety:0];
    txtView.placeholder = HYLocalizedString(@"请为您的照片添加一段描述(最多100个字)");
    txtView.contentInset = UIEdgeInsetsMake(10, 0, 10, 0);
    [txtView setBackgroundColor:[UIColor clearColor]];
    txtView.font = FONT_NORMAL;
    [self.view addSubview:txtView];
    [txtView becomeFirstResponder];
    
    UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(txtView.frame.origin.x+txtView.frame.size.width, 0, 1, rect.size.height+10)];
    [lbl setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.2]];
    [self.view addSubview:lbl];
 
    uploadImageView = [[UIImageView alloc]initWithFrame:CGRectMake(lbl.frame.origin.x + 8, 8, 75, 110)];
    uploadImageView.contentMode = UIViewContentModeScaleAspectFill;
    uploadImageView.clipsToBounds = YES;
    uploadImageView.userInteractionEnabled = YES;
    [uploadImageView setImage:[UIImage imageNamed:@"signup_logo"]];
    uploadImageView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:uploadImageView];
    
    UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectUploadImage:)];
    [uploadImageView addGestureRecognizer:g];
    
    UIImage *rorateImage = [UIImage imageNamed:@"rorate_image"];
    rorateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rorateBtn setFrame:CGRectMake(lbl.frame.origin.x + 17, uploadImageView.frame.origin.y + uploadImageView.frame.size.height + 10, rorateImage.size.width, rorateImage.size.height)];
    [rorateBtn addTarget:self action:@selector(rorateImageView:) forControlEvents:UIControlEventTouchUpInside];
    [rorateBtn setTitle:HYLocalizedString(@"旋转") forState:UIControlStateNormal];
    [rorateBtn.titleLabel setFont:FONT_NORMAL];
    [rorateBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,18, 0, 0)];
    [rorateBtn setBackgroundImage:rorateImage forState:UIControlStateNormal];
    [self.view addSubview:rorateBtn];
    
    toolBar = [[UIView alloc]initWithFrame:CGRectMake(0,rect.size.height+rect.origin.y,self.view.frame.size.width,44)];
    [toolBar setBackgroundColor:[UIColor colorWithWhite:0.754 alpha:1.000]];
    [self.view addSubview:toolBar];
    
    UIImage *addtag = [UIImage imageNamed:@"add_tag"];
    UIButton *addtagButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [addtagButton setBackgroundImage:[addtag stretchableImageWithLeftCapWidth:addtag.size.width/2 topCapHeight:0] forState:UIControlStateNormal];
    [addtagButton setTitle:HYLocalizedString(@"选择标签") forState:UIControlStateNormal];
    [addtagButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [addtagButton setFrame:CGRectMake(10,toolBar.frame.size.height/2 - addtag.size.height/2, addtag.size.width+10, addtag.size.height)];
    [addtagButton.titleLabel setFont:FONT_SMALL];
    [addtagButton addTarget:self action:@selector(addTag:) forControlEvents:UIControlEventTouchUpInside];
    [toolBar addSubview:addtagButton];
    
    UIImage *sina = [UIImage imageNamed:@"social_sina"];
    UIButton *sinaBlog = [UIButton buttonWithType:UIButtonTypeCustom];
    [sinaBlog setImage:sina forState:UIControlStateNormal];
    [sinaBlog setFrame:CGRectMake(toolBar.frame.size.width - sina.size.width - 10, toolBar.frame.size.height/2 - sina.size.height/2 - 2, sina.size.width, sina.size.height)];
    sinaBlog.transform = CGAffineTransformMakeScale(0.8, 0.8);
    [toolBar addSubview:sinaBlog];

    UIImage *tecent = [UIImage imageNamed:@"social_tecent"];
    UIButton *tecentBlog = [UIButton buttonWithType:UIButtonTypeCustom];
    [tecentBlog setFrame:CGRectMake(sinaBlog.frame.origin.x - tecent.size.width - 10, toolBar.frame.size.height/2 - tecent.size.height/2 - 2, tecent.size.width, tecent.size.height)];
    [tecentBlog setImage:tecent forState:UIControlStateNormal];
    tecentBlog.transform = CGAffineTransformMakeScale(0.8, 0.8);
    [toolBar addSubview:tecentBlog];
    
    UIImage *originImage = [UIImage imageNamed:@"origin_write"];
    UIButton *originBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [originBtn setFrame:CGRectMake(tecentBlog.frame.origin.x - 100 - 10, toolBar.frame.size.height/2 - originImage.size.height/2, 100, originImage.size.height)];
    [originBtn setImage:originImage forState:UIControlStateNormal];
    [originBtn.titleLabel setFont:FONT_NORMAL];
    [originBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [originBtn setTitle:HYLocalizedString(@"原创作品") forState:UIControlStateNormal];
    [originBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 8, 0, 0)];
    [toolBar addSubview:originBtn];
    
    tagsView = [[UIView alloc]initWithFrame:CGRectMake(0,toolBar.frame.size.height + toolBar.frame.origin.y, 320,180)];
    tagsView.backgroundColor = [UIColor whiteColor];
    tagsView.hidden = NO;
    [self.view addSubview:tagsView];
    
    tb = [[UITableView alloc]initWithFrame:CGRectMake(15, 0, 290, 180) style:UITableViewStylePlain];
    tb.dataSource = self;
    tb.delegate = self;
    [tagsView addSubview:tb];

}

-(void)addTag:(UIButton *)tag
{
    [txtView resignFirstResponder];
}


//添加事件过滤ios5中uibutton无法相应的问题
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return ! ([touch.view isKindOfClass:[UIControl class]]);
}



- (void)viewDidLoad
{
    [self setTitle:HYLocalizedString(@"秀照片") showBackButton:!isModalViewController];

    [super viewDidLoad];

    [self registerForKeyboardNotifications];


    [self setRightItem:HYLocalizedString(@"上传")];
}


-(void)rightBarButtonItemAction:(UIButton *)btn
{
    if (isSelectImage)
    {
        [self uploadImage:uploadImageView.image];
    }
    else
    {
        [MSTool showAlert:HYLocalizedString(@"请先选择图片")];
    }
}


-(void)configureViews:(BOOL)animation
{
    if (isModalViewController)
    {
        self.navigationItem.hidesBackButton = YES;
        self.navigationItem.backBarButtonItem = nil;
        UIImage *btnImage = [UIImage imageNamed:@"nav_btn_back"];
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setFrame:CGRectMake(0, 0, btnImage.size.width, btnImage.size.height)];
        [btn setBackgroundImage:[btnImage stretchableImageWithLeftCapWidth:2 topCapHeight:2] forState:UIControlStateNormal];
        btn.tag = 1;
        [btn addTarget:self action:@selector(dismissViewController:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
        self.navigationItem.leftBarButtonItem = leftItem;
    }
}

-(void)dismissViewController:(UIButton *)btn
{
    [[MSAppDelegate sharedAppDelegate]dismissViewControl];
}

- (void) keyboardWasShown:(NSNotification *) notif
{
    NSDictionary *info = [notif userInfo];
    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey
                      ];
    CGSize keyboardSize = [value CGRectValue].size;
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:0.30];
    toolBar.frame=CGRectMake(toolBar.frame.origin.x,self.view.frame.size.height-keyboardSize.height+4.0-44,
                               toolBar.frame.size.width,
                               toolBar.frame.size.height);
    txtView.frame = CGRectMake(0,0, txtView.frame.size.width, toolBar.frame.origin.y);
    UIViewSetFrameY(tagsView, toolBar.frame.size.height + toolBar.frame.origin.y);
	[UIView commitAnimations];
}

- (void) keyboardWasHidden:(NSNotification *) notif
{
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:0.30];
    txtView.frame = CGRectMake(0,0, txtView.frame.size.width,156);
    toolBar.frame=CGRectMake(toolBar.frame.origin.x,txtView.frame.origin.y+txtView.frame.size.height+10,
                               toolBar.frame.size.width,
                               toolBar.frame.size.height);
    UIViewSetFrameY(tagsView, toolBar.frame.size.height + toolBar.frame.origin.y);
	[UIView commitAnimations];
}


- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    return YES;
}

- (void)textInputChanged:(NSNotification *)notif
{
    NSString *txtString = [MSTool trimmingWhiteSpaceCharacter:txtView.text];
    NSInteger count = [txtString length];
    if (count > maxCount)
    {
        count = maxCount;
        txtView.text = [txtString substringToIndex:count];
        [[HYProgressHUD sharedProgressHUD]setText:HYLocalizedString(@"亲，超过字数限制了!")];
        [[HYProgressHUD sharedProgressHUD]showInView:[[[UIApplication sharedApplication] windows] lastObject]];
        [[HYProgressHUD sharedProgressHUD]done:NO];
    }
}


- (void) registerForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasHidden:) name:UIKeyboardWillHideNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(textInputChanged:)
                                                 name:UITextViewTextDidChangeNotification
                                               object:nil];
}

-(void)removeNotifications
{
	[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    
	[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UITextViewTextDidChangeNotification object:nil];
}


-(void)rorateImageView:(UIButton *)btn
{
    UIImageOrientation or;
    switch (uploadImageView.image.imageOrientation)
    {
        case UIImageOrientationUp:
            or = UIImageOrientationRight;
            break;
        case UIImageOrientationRight:
            or = UIImageOrientationDown;
            break;
        case UIImageOrientationDown:
            or = UIImageOrientationLeft;
            break;
        case UIImageOrientationLeft:
            or = UIImageOrientationUp;
            break;
        default:
            or = uploadImageView.image.imageOrientation;
            break;
    }
    uploadImageView.image = [UIImage imageWithCGImage:uploadImageView.image.CGImage scale:1.0 orientation:or];
}


-(void)selectUploadImage:(id)sender
{
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:HYLocalizedString(@"取消") destructiveButtonTitle:nil otherButtonTitles:HYLocalizedString(@"拍照"),HYLocalizedString(@"从相册选择"), nil];
    sheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    [sheet showInView:self.navigationController.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == actionSheet.cancelButtonIndex)
    {
        return;
    }
    else if(buttonIndex == 0)
    {
        [self performSelector:@selector(takePhoto) withObject:nil afterDelay:0.0];
    }
    else if(buttonIndex == 1)
    {
        [self performSelector:@selector(openPhotoLibrary) withObject:nil afterDelay:0.0];
    }
}

-(void)openPhotoLibrary
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = NO;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
}

//take a photo from camera
-(void)takePhoto
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
	{
		UIImagePickerController *picker = [[UIImagePickerController alloc] init];
		picker.delegate = self;
		picker.allowsEditing = NO;
		picker.sourceType = UIImagePickerControllerSourceTypeCamera;
		[self presentModalViewController:picker animated:YES];
	}
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"设备不支持拍照" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}


#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *editImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    NSAssert(editImage != nil, @"Can't get the image!");
	if (editImage)
	{
        self.uploadImageView.image = editImage;
        isSelectImage = YES;
    }
	[picker dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissModalViewControllerAnimated:YES];
}


#pragma #
#pragma 上传照片
-(void)uploadImage:(UIImage *)image
{
    NSDictionary *p = [NSDictionary dictionaryWithObjectsAndKeys:
                       APISendPrivateImageMessage,@"action",
                       nil];
    [WebService uploadImage:image param:p labelText:HYLocalizedString(@"发送图片") success:^(NSDictionary *info,NSError *error)
     {
         HYLog(@"%@",info);
         NSDictionary *result = [info objectForKey:@"result"];
         if (result && [result isKindOfClass:[NSDictionary class]] &&[result count]>0)
         {
             [self shareUploadImage:[result objectForKey:@"imgs"]];
         }
     } failure:^(id info ,NSError *error){
         [MSTool showAlert:error.localizedDescription];
     }];
}


-(void)shareUploadImage:(NSString *)img
{    
    NSString *tags = @"";
    
    for (int i = 0 ; i < 7; i ++)
    {
        NSString *key = [NSString stringWithFormat:@"%d",i];
        NSString *tag = [tagsDict objectForKey:key];
        if (tag && ![tag isEqual:[NSNull null]] && [tag length]>0)
        {
            tags = [tags stringByAppendingFormat:@"%@",tag];
            if (i != 6)tags = [tags stringByAppendingFormat:@" "];
        }
    }
    
    NSString *specialty = @"0";
    NSString *gid = [[MSSetting sharedSetting]getGid];
    
    if (gid && [gid isEqualToString:@"8"])
        specialty = @"1";
        
    NSDictionary *p = [NSDictionary dictionaryWithObjectsAndKeys:
                       [[MSSetting sharedSetting]getAccountID],@"uid",
                       [NSArray arrayWithObject:img],@"pics",
                       specialty,@"specialty",
                       txtView.text,@"content",
                       tags,@"tags",
                       nil];
    HYLog(@"%@",p);

    [WebService  getRequestAction:APIShareUploadImage
                            param:p
                          success:^(NSDictionary *info,NSError *error)
     {
         HYLog(@"%@",info);
         if (error == nil)
         {
             [MSTool showAlert:HYLocalizedString(@"分享成功!")];
             [self dismissViewController:nil];
         }
         [MSTool showError:error];
     } failure:^(id info ,NSError *error){
         [MSTool showError:error];
     } progress:[[[UIApplication sharedApplication] windows] lastObject]];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [tbArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0,320.0f,100.0f)];
        view.tag = 2;
        [cell.contentView addSubview:view];
    }
    
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary *item = [tbArray objectAtIndex:indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@:",[item objectForKey:@"title"]];
    cell.textLabel.font = [UIFont systemFontOfSize:12.0f];
    
    UIView *v = [cell.contentView viewWithTag:2];
    [v.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    NSArray *btns = [item objectForKey:@"array"];
    CGFloat btn_x =  45.0f;
    CGFloat btn_y = 6.0f;
    
    for (int j = 0 ; j < [btns count]; j++)
    {
        NSString *btntitle = [btns objectAtIndex:j];
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setFrame:CGRectMake(btn_x,btn_y,0,25.0f)];
        [btn setTitle:btntitle forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:12.0f];
        [btn.titleLabel setTextAlignment:UITextAlignmentCenter];
        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [btn setBackgroundColor:[UIColor clearColor]];
        [btn sizeToFit];
        CGRect btnFrame = btn.frame;
        btnFrame.size.width += 10;
        btnFrame.size.height += 8;
        btn.frame = btnFrame;
        btn.layer.cornerRadius = 6.0f;
        btn.layer.masksToBounds = YES;
        [btn addTarget:self action:@selector(tagClick:) forControlEvents:UIControlEventTouchUpInside];
        [v addSubview:btn];
        
        NSString *tag =  [tagsDict objectForKey:[NSString stringWithFormat:@"%d",indexPath.row]];
        HYLog(@"%@",tag);
        
        if (tag && [tag isEqualToString:btntitle])
        {
            HYLog(@"%@",tag);
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [btn setBackgroundColor:[UIColor colorWithRed:1.000 green:0.331 blue:0.604 alpha:1.000]];
        }
        
        btn_x += (btn.frame.size.width+15.0f);
        
        if (indexPath.row == [tbArray count]-1 && j > 3)
        {
            btn_y = 37.0f;
            if (j == 4) btn_x = 45.0f;
        }
    }
    
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row+1 == [tbArray count])
    {
        return 66.0f;
    }
    return 35.0f;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


-(void)tagClick:(UIButton *)btn
{
    UIView *v = btn.superview;
    for(UIButton *btn in v.subviews)
    {
        [btn setBackgroundColor:[UIColor clearColor]];
        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    }
    
    UITableViewCell *cell = (UITableViewCell *)v.superview.superview;
    NSIndexPath *indexPath =  [tb indexPathForCell:cell];
    [tagsDict setObject:btn.titleLabel.text forKey:[NSString stringWithFormat:@"%d",indexPath.row]];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor colorWithRed:1.000 green:0.331 blue:0.604 alpha:1.000]];
    
    HYLog(@"_tagsDict---》%@",tagsDict);
    
    NSString *tags = @"";
    for (int i = 0 ; i < 7; i ++)
    {
        NSString *key = [NSString stringWithFormat:@"%d",i];
        NSString *tag = [tagsDict objectForKey:key];
        if (tag && ![tag isEqual:[NSNull null]] && [tag length]>0)
        {
            tags = [tags stringByAppendingFormat:@"%@",tag];
            if (i != 6)tags = [tags stringByAppendingFormat:@"、"];
        }
    }
    
    if (tags && [tags length]>0)
    {
//        self.tagTextView.text = [NSString stringWithFormat:@"标签：%@",tags];
    }
    else
    {
//        self.tagTextView.text = [NSString stringWithFormat:@"标签：没有任何标签，点击这里添加"];
    }
}



-(void)dealloc
{
    [self removeNotifications];
    [[NSNotificationCenter defaultCenter] removeObserver:self];\
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
